CLS
RANDOMIZE TIMER
INPUT "vvedite razmer massiva"; n
INPUT "vvedite chislo"; c
DIM a(n)
FOR i = 1 TO n
a(i) = FIX(RND(i) * 100 - 50)
NEXT
min = ABS(a(1) - c)
FOR i = 1 TO n
IF ABS(a(i) - c) < min THEN min = ABS(a(i) - c): q = a(i): k = i
NEXT
CLS
FOR i = 1 TO n
PRINT a(i);
NEXT
PRINT
PRINT "chislo ="; c
PRINT "blizhajshee chislo ="; q; "nomer elementa"; k
Тестирование выполнено в программе QB64 ( Скачать )